import request from '@/utils/request'
// import qs from 'qs'

// SNAT

// 获取列表
export function getSnatArray (params) {
  var data = fromData(params)
  return request({
    url: 'snat/getSnatArray',
    method: 'post',
    data
  })
}

// 添加SNAT规则
export function addSnat (params) {
  var data = fromData(params)
  return request({
    url: 'snat/addSnat',
    method: 'post',
    data
  })
}

// 删除SNAT规则
export function delSnat (params) {
  var data = fromData(params)
  return request({
    url: 'snat/del_snat',
    method: 'post',
    data
  })
}

// 编辑SNAT规则
export function editSnat (params) {
  var data = fromData(params)
  return request({
    url: 'snat/editSnat',
    method: 'post',
    data
  })
}

// 清空SNAT规则
export function clearSnat (params) {
  var data = fromData(params)
  return request({
    url: 'snat/clear_snat',
    method: 'post',
    data
  })
}

// function fromData (params) {
//   var data = qs.stringify(params)
//   return data
// }

function fromData (params) {
  let formData = new FormData()
  for (const it in params) {
    if (!Object.is(params[it], null) && !Object.is(params[it], '')) {
      formData.append(it, params[it])
    }
  }
  return formData
}
